/*
 * @Author: wangshuguang
 * @Date: 2022-12-27 17:22:25
 * @LastEditTime: 2023-01-04 17:39:34
 * @LastEditors: wangshuguang
 * @Description: 校验文本是否命中关键字
 */

import { checkWord } from "@/api/sensitiveWord";
import { Toast } from 'vant';

/**
 * @description: 
 * @param {*} word 检测文本
 * @return {*} 返回命中关键字，为空则没有命中关键字
 */
export const checkWordFun = (word) => {
  return new Promise((resolve, reject) => {
    checkWord({word}).then(res => {
      const {data} = res.data
      if(data){
        // 将数组关键字转为字符串
        resolve(data.toString())
      }else{
        resolve('')
      }
    }).catch(reject)
  })
}

// 基础form校验rule
export const checkWordBaseFormRule = {
  message: '关键字检索异常',
  validator: (value) => {
    return checkWordFun(value).then(res => {
      if(res){
        // 不需要展示详细关键字
        // Toast.fail(`请勿包含关键字：${res}`)
        return false
      }else{
        return true
      }
    })
  },
}